package com.weixin.engine.design.single.lazy;

/**
 * 懒汉模式-线程安全，适用于多线程
 */
public class LazySafeSingleton {
    private static volatile LazySafeSingleton safeSingleton;//防止指令重排

    private LazySafeSingleton() {
    }

    public static LazySafeSingleton getInstance() {
        if (safeSingleton == null) {
            synchronized (LazySafeSingleton.class) {
                if (safeSingleton == null) {//双重检测
                    safeSingleton = new LazySafeSingleton();
                }
            }

        }
        return safeSingleton;
    }
}